//
//  issuedVC.m
//  HappyStore
//
//  Created by 陈锋 on 16/6/15.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "issuedVC.h"
#import "SearchProjectCell.h"
#import "SearchPriceCell.h"
#import "BusinessActCell.h"
#import "UsedTool.h"
#import "SoftwareCell.h"
#import "serviceInfo.h"
#import "SoftEnterpriseCell.h"
#import "SearchProjectInfoVC.h"
#import "SearchPriceDetail.h"
#import "BusinessActInfo.h"

#import "LSBecomeVIPVC.h"
#import "LSRechargeVC.h"
#import "ForgetPassWord.h"
#import "LSPayResultVC.h"
@interface issuedVC (){
    NSMutableArray *_aryInfo;
    NSMutableDictionary *muDicParameters;
    NSInteger paggge;
    
    NSString * or_Number;
    NSString * fundsId;
    BOOL  isSetPayPass;
    NSString * projectId;
    double price;
}

@property (strong, nonatomic) LSPromptAlertVC * LSPromptAlert;
@end

static NSString * SearchProjectcell = @"SearchProjectCell";
static NSString * SearchPricecell = @"SearchPriceCell";
static NSString * BusinessActcell = @"BusinessActCell";
static NSString * Softwarecell = @"SoftwareCell";
static NSString * SoftEnterprisecell = @"SoftEnterpriseCell";
@implementation issuedVC

-(LSPromptAlertVC *)LSPromptAlert{
    
    if (!_LSPromptAlert) {
        _LSPromptAlert = [[LSPromptAlertVC alloc]init];
    }
    return _LSPromptAlert;
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.tabBarController.tabBar.hidden = YES;
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16.f],NSFontAttributeName,[UIColor whiteColor],NSForegroundColorAttributeName,nil]];

        paggge = 1;
        muDicParameters = [NSMutableDictionary dictionary];
        [muDicParameters setObject:[NSString stringWithFormat:@"%ld",(long)paggge] forKey:@"page"];//页码
        [muDicParameters setObject:self.userId forKey:@"userId"];//类型
        [muDicParameters setObject:self.userType forKey:@"userType"];//类型
        [self startSearch];

}
- (void)viewDidLoad {
    [super viewDidLoad];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text =self.titleStr;
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
//    self.title = self.titleStr;
    
    //注册
    UINib * nib = [UINib nibWithNibName:@"SearchProjectCell" bundle:nil];
    
    [self.tableView registerNib:nib forCellReuseIdentifier:SearchProjectcell];
    
    UINib * nib1 = [UINib nibWithNibName:@"SearchPriceCell" bundle:nil];
    
    [self.tableView registerNib:nib1 forCellReuseIdentifier:SearchPricecell];
    
    UINib * nib2 = [UINib nibWithNibName:@"BusinessActCell" bundle:nil];
    
    [self.tableView registerNib:nib2 forCellReuseIdentifier:BusinessActcell];
    
    UINib * nib3 = [UINib nibWithNibName:@"SoftwareCell" bundle:nil];
    
    [self.tableView registerNib:nib3 forCellReuseIdentifier:Softwarecell];
    
    UINib * nib4 = [UINib nibWithNibName:@"SoftEnterpriseCell" bundle:nil];
    
    [self.tableView registerNib:nib4 forCellReuseIdentifier:SoftEnterprisecell];
    
    //取消返回的文字
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
    
    
    _aryInfo = [NSMutableArray array];
    paggge = 1;
    
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        if (_aryInfo.count != 0) {
            NSString *path = [[NSBundle mainBundle]pathForResource:@"refresh"
                                                            ofType:@"wav"];
            SystemSoundID soundID;
            AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
            AudioServicesPlaySystemSound(soundID); //仅播放音频
            
            paggge = 1;
            [muDicParameters setObject:@"1" forKey:@"page"];
            [muDicParameters setObject:self.userId forKey:@"userId"];//类型
            [muDicParameters setObject:self.userType forKey:@"userType"];//类型
            [self startSearch];
        }else {
            [self.tableView.mj_header endRefreshing];
        }
    }];
    
    
    
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        paggge += 1;
        [muDicParameters setObject:[NSString stringWithFormat:@"%ld",(long)paggge] forKey:@"page"];
        [self startSearch];
    }];
    
    self.tableView.mj_footer.hidden = YES;

    if (muDicParameters == nil) {
        muDicParameters = [NSMutableDictionary dictionary];
        [muDicParameters setObject:@"1" forKey:@"page"];
        [muDicParameters setObject:self.userId forKey:@"userId"];//类型
        [muDicParameters setObject:self.userType forKey:@"userType"];//类型
    }
    
    [self showRoundProgressWithTitle:@"请稍后..."];

    
    
    // 设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"Back" highImage:@"Back"];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    //监听按钮
    [self.LSPromptAlert.PromptAlertView.becomeVIPBtn addTarget:self action:@selector(clickBecomeVIPBtn) forControlEvents:UIControlEventTouchUpInside];
    
    [self.LSPromptAlert.PromptAlertView.alipayBtn addTarget:self action:@selector(clickAlipayBtn) forControlEvents:UIControlEventTouchUpInside];
    
    [self.LSPromptAlert.PromptAlertView.balancePayBtn addTarget:self action:@selector(clickCashBtn) forControlEvents:UIControlEventTouchUpInside];
    
    //支付回调通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentView) name:@"alipayResult" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentFailedView) name:@"alipayFailed" object:nil];
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}

-(void)leftBarButtonItemClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    [tableView tableViewDisplayWitMsg:@"没有查询到相对应的数据" ifNecessaryForRowCount:_aryInfo.count];
    return _aryInfo.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.titleStr isEqualToString:@"项目"]) {
        return 103;
    }else return 150;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([self.titleStr isEqualToString:@"项目"]) {
        SearchProjectCell *cell = [tableView dequeueReusableCellWithIdentifier:SearchProjectcell];
        tableView.rowHeight = UITableViewAutomaticDimension;
        
        cell.TitleLabel.text = _aryInfo[indexPath.row][@"title"];
        
        cell.AddressLabel.text = _aryInfo[indexPath.row][@"address"];
        
        cell.IndustryLabel.text = _aryInfo[indexPath.row][@"industry"];
        
        cell.PriceLabel.text = [CustomExcetion comperNumber:_aryInfo[indexPath.row][@"investment"]];

        if ([_aryInfo[indexPath.row][@"type"] isEqualToString:@"政府"]) {
            
            cell.ProjectIconImageView.image = [UIImage imageNamed:@"政府"];
        }else if ([_aryInfo[indexPath.row][@"type"] isEqualToString:@"企业"]){
            
            cell.ProjectIconImageView.image = [UIImage imageNamed:@"企业"];
        }else{
            
            cell.ProjectIconImageView.image = [UIImage imageNamed:@"个人"];
        }
        
        return cell;
        
    }else if ([self.titleStr isEqualToString:@"资金"]){
        SearchPriceCell *cell = [tableView dequeueReusableCellWithIdentifier:SearchPricecell];
        
        NSDictionary *dic = _aryInfo[indexPath.row];
        
        //设置圆形头像
        [cell.headPhoto.layer setCornerRadius:cell.headPhoto.frame.size.height/2];
        [cell.headPhoto.layer setMasksToBounds:YES];
        [cell.headPhoto setContentMode:UIViewContentModeScaleAspectFill];
        [cell.headPhoto setClipsToBounds:YES];
        cell.headPhoto.layer.shadowColor = [UIColor blackColor].CGColor;
        cell.headPhoto.layer.shadowOffset = CGSizeMake(4, 4);
        cell.headPhoto.layer.shadowOpacity = 0.5;
        cell.headPhoto.layer.shadowRadius = 2.0;
        cell.headPhoto.userInteractionEnabled = YES;
        
        [cell.headPhoto sd_setImageWithURL:_aryInfo[indexPath.row][@"headPhoto"] placeholderImage:[UIImage imageNamed:@"20100403114758394_4147"]];
        
        
        
        cell.commentUserName.text = dic[@"userName"];
        if (dic[@"userName"]==nil || [dic[@"userName"] isEqualToString:@""] || [dic[@"userName"] isEqualToString:@"null"]) {
            cell.commentUserName.text = _aryInfo[indexPath.row][@"account"];
        }
        
        
        cell.posiTion.text = dic[@"posiTionName"];
        if (dic[@"posiTionName"]==nil||[dic[@"posiTionName"] isEqualToString:@"null"]) {
            cell.posiTion.text = @"";
        }
        
//        if ([dic[@"authState"] integerValue] == 2) {
//            
//            cell.authStateImageView.image = [UIImage imageNamed:@"yirenzheng"];
//        }else{
//            
//            cell.authStateImageView.image = [UIImage imageNamed:@"weirenzheng"];
//        }
        //认证
        cell.isAuthState.hidden = [UsedTool authStateImageViewHidden:dic[@"authState"]];
        //会员图标
        cell.authStateImageView.image = [UsedTool setVipimage:dic[@"vipLevel"]];
        cell.titleLabel.text = dic[@"title"];
        
        cell.priceLabel.text = [CustomExcetion comperNumber:dic[@"investment"]];

        
        
        //判断上级
        cell.companyUserName.text = [UsedTool userType:dic[@"userType"] companyName:dic[@"companyName"] userAddress:dic[@"userAddress"]];
        return cell;
        
    }else if ([self.titleStr isEqualToString:@"活动"]){
        
        BusinessActCell *cell = [tableView dequeueReusableCellWithIdentifier:BusinessActcell];
        
        NSDictionary *dicData = [NSDictionary dictionaryWithDictionary:_aryInfo[indexPath.row]];
        
        [cell.photoImageView sd_setImageWithURL:[NSURL URLWithString:dicData[@"logo"]] placeholderImage:[UIImage imageNamed:@"img_normal3"]];
        cell.titleLabel.text = dicData[@"title"];
        cell.addressLabel.text = dicData[@"address"];
        //时间
        NSString *timeStr = dicData[@"createtime"];
        //年月日
        NSString *yearStr = [timeStr substringToIndex:10];
        //几点
        NSString *timeString = [timeStr substringWithRange:NSMakeRange(10,6)];
        //周几
        NSString *weekStr = [UsedTool getWeekDayForstring:timeStr];
        
        cell.timeLabel.text = [NSString stringWithFormat:@"%@ %@ %@",yearStr,weekStr,timeString];
        //标签
        NSArray *arrayLabel = [dicData[@"lable"] componentsSeparatedByString:@","];
        if (arrayLabel.count>0) {
            
            cell.labelLabel.layer.borderWidth = 0.5f;
            cell.labelLabel.layer.borderColor = RGB(23, 176, 216).CGColor;
            cell.labelLabel.backgroundColor = RGB(217, 242, 255);
            cell.labelLabel.text = arrayLabel[0];
            CGSize size = [cell.labelLabel sizeThatFits:CGSizeMake(MAXFLOAT, 18)];
            cell.labelWidthConstraint.constant = size.width +10;
            
        }
        if (arrayLabel.count>1) {
            cell.labelLabelTwo.layer.borderWidth = 0.5f;
            cell.labelLabelTwo.layer.borderColor = RGB(23, 176, 216).CGColor;
            cell.labelLabelTwo.backgroundColor = RGB(217, 242, 255);
            cell.labelLabelTwo.text = arrayLabel[1];
            CGSize sizeTwo = [cell.labelLabelTwo sizeThatFits:CGSizeMake(MAXFLOAT, 18)];
            cell.labelWidthConstraintTwo.constant = sizeTwo.width +10;
        }
        if (arrayLabel.count==1) {
            cell.labelLabelTwo.text = @"";
            cell.labelWidthConstraintTwo.constant = 0;
        }

        
        return cell;
    }else if ([self.titleStr isEqualToString:@"服务"]){
        NSDictionary *dicData = _aryInfo[indexPath.row];
        
        if ([dicData[@"userType"] integerValue] == 2) {
            
            //企业
            static NSString * cellId = @"serviceCellID";
            SoftEnterpriseCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (!cell) {
                cell = [[SoftEnterpriseCell alloc] init];
            }
            cell.titleLabel.text = dicData[@"title"];
            //设置圆形头像
            [cell.headPhoto.layer setCornerRadius:cell.headPhoto.frame.size.height/2];
            [cell.headPhoto.layer setMasksToBounds:YES];
            [cell.headPhoto setContentMode:UIViewContentModeScaleAspectFill];
            [cell.headPhoto setClipsToBounds:YES];
            cell.headPhoto.layer.shadowColor = [UIColor blackColor].CGColor;
            cell.headPhoto.layer.shadowOffset = CGSizeMake(4, 4);
            cell.headPhoto.layer.shadowOpacity = 0.5;
            cell.headPhoto.layer.shadowRadius = 2.0;
            cell.headPhoto.userInteractionEnabled = YES;
            [cell.headPhoto sd_setImageWithURL:dicData[@"headPhoto"] placeholderImage:[UIImage imageNamed:@"project_detail_taoxin_normal"]];
            
            cell.addressLabel.text = dicData[@"address"];
            
            
            //自定义的label
            UILabel *label = [[UILabel alloc] init];
            if (dicData[@"userName"] == nil ||[dicData[@"userName"] isEqualToString:@""]||[dicData[@"userName"] isEqualToString:@"null"]) {
                label.text = dicData[@"account"];
            }else{
                label.text = dicData[@"userName"];
            }
            label.numberOfLines = 1;
            label.font = [UIFont systemFontOfSize:17];
            label.textColor = cell.companyName.textColor;
            CGSize size = [label.text sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(MAXFLOAT, 21)];
            if (size.width > screenW-140) {
                size.width = screenW-140;
            }
            
            CGRect frameC = cell.companyName.frame;
            frameC.size.width = size.width;
            label.frame = frameC;
            [cell addSubview:label];
            
            UIImageView *authImageView = [[UIImageView alloc] initWithFrame:CGRectMake(label.frame.origin.x+label.frame.size.width+8, label.frame.origin.y+3, 15, 15)];
            
            
//            if ([dicData[@"authState"] integerValue] == 2) {
//                //已认证
//                authImageView.image = [UIImage imageNamed:@"yirenzheng"];
//            }else{
//                
//                authImageView.image = [UIImage imageNamed:@"weirenzheng"];
//            }
            //认证
            cell.isAuthState.hidden = [UsedTool authStateImageViewHidden:dicData[@"authState"]];
            //会员图标
            authImageView.image = [UsedTool setVipimage:dicData[@"vipLevel"]];
            [cell addSubview:authImageView];
            
            return cell;
        }else{
            
            //个人
            static NSString *cellIdentifier = @"serviceCell";
            SoftwareCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
            if (!cell) {
                cell = [[SoftwareCell alloc] init];
            }
            
            NSDictionary *dicData = _aryInfo[indexPath.row];
            cell.titleLabel.text =dicData[@"title"];
            
            
            //设置圆形头像
            [cell.headPhotoImageView.layer setCornerRadius:cell.headPhotoImageView.frame.size.height/2];
            [cell.headPhotoImageView.layer setMasksToBounds:YES];
            [cell.headPhotoImageView setContentMode:UIViewContentModeScaleAspectFill];
            [cell.headPhotoImageView setClipsToBounds:YES];
            cell.headPhotoImageView.layer.shadowColor = [UIColor blackColor].CGColor;
            cell.headPhotoImageView.layer.shadowOffset = CGSizeMake(4, 4);
            cell.headPhotoImageView.layer.shadowOpacity = 0.5;
            cell.headPhotoImageView.layer.shadowRadius = 2.0;
            cell.headPhotoImageView.userInteractionEnabled = YES;
            
            [cell.headPhotoImageView sd_setImageWithURL:dicData[@"headPhoto"] placeholderImage:[UIImage imageNamed:@"project_detail_taoxin_normal"]];
            
            if (dicData[@"userName"] == nil ||[dicData[@"userName"] isEqualToString:@""]||[dicData[@"userName"] isEqualToString:@"null"]) {
                cell.commentUserName.text = dicData[@"account"];
            }else{
                cell.commentUserName.text = dicData[@"userName"];
            }
            
            cell.posiTion.text = dicData[@"posiTionName"];
            if (dicData[@"posiTionName"]==nil||[dicData[@"posiTionName"] isEqualToString:@"null"]) {
                cell.posiTion.text = @"";
            }
            
//            if ([dicData[@"authState"] integerValue] == 2) {
//                
//                cell.authStateImageView.image = [UIImage imageNamed:@"yirenzheng"];
//            }else{
//                
//                cell.authStateImageView.image = [UIImage imageNamed:@"weirenzheng"];
//            }
            //认证
            cell.isAuthState.hidden = [UsedTool authStateImageViewHidden:dicData[@"authState"]];
            //会员图标
            cell.authStateImageView.image = [UsedTool setVipimage:dicData[@"vipLevel"]];
            
            //判断上级
            cell.companyUserName.text = [UsedTool userType:dicData[@"userType"] companyName:dicData[@"companyName"] userAddress:dicData[@"userAddress"]];
            return cell;
        }

    }
    else return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];//取消选中状态
    
    if (allConstMemberid) {
        
        //取消显示后退键文字
        UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
        self.navigationItem.backBarButtonItem = barButtonItem;
        
        if ([self.titleStr isEqualToString:@"项目"]) {
            
            [self showRoundProgressWithTitle:@"请稍后..."];
            
            NSMutableDictionary * dict = [NSMutableDictionary dictionary];
            dict[@"projectId"] = _aryInfo[indexPath.row][@"projectId"];
            dict[@"userId"] = allConstMemberid;
            
            [LSHttpTool sendHttpData:@"projectDetail_app_project.im" params:dict success:^(id responseObject) {
                NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
                
                if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                    
                    [self.LSPromptAlert dismissViewControllerAnimated:YES completion:nil];
                    
                    SearchProjectInfoVC * SeaVC = [[SearchProjectInfoVC alloc]initWithNibName:@"SearchProjectInfoVC" bundle:nil];
                    SeaVC.dataDict = dicInfo[@"data"];
                    SeaVC.projectData = [NSMutableArray arrayWithArray:dicInfo[@"data"][@"commentsList"]];
                    SeaVC.tig = @"project";
                    
                    [self.navigationController pushViewController:SeaVC animated:YES];
                    
                }else if ([[dicInfo objectForKey:@"result"] integerValue] == 2){

                    [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                    
                }else if ([[dicInfo objectForKey:@"result"]integerValue] == 3){
                    
                    isSetPayPass = [dicInfo[@"data"][@"isSetPayPass"] boolValue];
                    price = [dicInfo[@"data"][@"powerMoney"]floatValue];
                    
                    projectId = _aryInfo[indexPath.row][@"projectId"];
                    
                    self.LSPromptAlert.modalPresentationStyle=UIModalPresentationOverCurrentContext;
                    [self presentViewController:self.LSPromptAlert animated:YES completion:nil];
                    
                }
                
                [self hideBubble];
            } failure:^(NSError *error) {
                

                [self showSingleIconBubble:@"网络连接错误"];
                
            }];
            
        }else if ([self.titleStr isEqualToString:@"资金"]){
            
            [self showRoundProgressWithTitle:@"请稍后..."];
            
            NSMutableDictionary *muDicParameter = [NSMutableDictionary dictionary];
            
            muDicParameter[@"fundsId"] = _aryInfo[indexPath.row][@"fundsId"];
            muDicParameter[@"userId"] = allConstMemberid;
            
            NSString *strURL = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"fundsDetail_app_funds.im"];
            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            
            [manager POST:strURL parameters:muDicParameter progress:^(NSProgress * _Nonnull uploadProgress) {
                
            } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
                
                [self hideBubble];
                
                if ([dicInfo[@"result"] integerValue] ==1) {
                    
                    SearchPriceDetail *Svc = [[SearchPriceDetail alloc] initWithNibName:@"SearchPriceDetail" bundle:nil];
                    
                    Svc.dicData = dicInfo[@"data"];
                    Svc.commentsList = dicInfo[@"data"][@"commentsList"];
                    Svc.tig = @"price";
                    
                    [self.navigationController pushViewController:Svc animated:YES];
                    
                }else if ([[dicInfo objectForKey:@"result"] integerValue] == 2){
                    
                    [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                    
                }else if ([[dicInfo objectForKey:@"result"]integerValue] == 3){
                    
                    isSetPayPass = [dicInfo[@"data"][@"isSetPayPass"] boolValue];
                    price = [dicInfo[@"data"][@"powerMoney"]floatValue];
                    fundsId = _aryInfo[indexPath.row][@"fundsId"];
                    
                    self.LSPromptAlert.modalPresentationStyle=UIModalPresentationOverCurrentContext;
                    [self presentViewController:self.LSPromptAlert animated:YES completion:nil];
                    
                }
                
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

               [self showSingleIconBubble:error.localizedDescription];
                
            }];
            
        }else if ([self.titleStr isEqualToString:@"活动"]){
            
            BusinessActInfo *businessVC = [[BusinessActInfo alloc] init];
            businessVC.activityId = _aryInfo[indexPath.row][@"activityId"];
            [self.navigationController pushViewController:businessVC animated:YES];
            
        }else if ([self.titleStr isEqualToString:@"服务"]){
            
            //推出详细界面
            serviceInfo *serviceInfoVC = [[serviceInfo alloc] initWithNibName:@"serviceInfo" bundle:nil];
            serviceInfoVC.tig = @"service";
            serviceInfoVC.serviceId = _aryInfo[indexPath.row][@"serviceId"];
            [self.navigationController pushViewController:serviceInfoVC animated:YES];
        }
        
    }else{
    
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"请先登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登录", nil];
        
        alert.tag = 10;
        
        [alert show];
    
    }

}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 1;
}

#pragma mark - 弹框按钮监听
//跳转会员界面
-(void)clickBecomeVIPBtn{
    
    [self.LSPromptAlert dismissViewControllerAnimated:YES completion:nil];
    
    LSBecomeVIPVC * LSBecomeVIP = [[LSBecomeVIPVC alloc]init];
    [self.navigationController pushViewController:LSBecomeVIP animated:YES];
    
}

#pragma mark - 支付回调通知
-(void)clickAlipayBtn{
    
    if ([self.titleStr isEqualToString:@"项目"]) {
    
    or_Number = [LSAlipay alipay:@"乐商网" body:@"项目详情" price:price];
    
    }else if ([self.titleStr isEqualToString:@"资金"]){
    
    or_Number = [LSAlipay alipay:@"乐商网" body:@"资金详情" price:price];
    
    }
    
}

-(void)presentFailedView{
    
    // 跳转至支付失败页面
    LSPayResultVC * LSPayResult = [[LSPayResultVC alloc]init];
    [LSPayResult setCashTypeWithCashFailed];
    [self.navigationController pushViewController:LSPayResult animated:YES];
    
}

-(void)presentView{
    
    [self.LSPromptAlert dismissViewControllerAnimated:YES completion:nil];
    [self showRoundProgressWithTitle:@"请稍后..."];
    
    NSMutableDictionary * dic = [NSMutableDictionary  dictionary];
    dic[@"token"] = allConstMemberToken;
    dic[@"payUserId"] = allConstMemberid;
    dic[@"payWay"] = @"2";
    dic[@"payMoney"] = @(price);
    dic[@"order_no"] = or_Number;
    NSString * str;
    
    if ([self.titleStr isEqualToString:@"项目"]) {
        
        str = @"buyProjectDetail_app_pay.im.lensum";
        dic[@"resId"] = projectId;
        
    }else if ([self.titleStr isEqualToString:@"资金"]){
        
        str = @"buyFundsDetail_app_pay.im.lensum";
        dic[@"resId"] = fundsId;
        
    }
    
    [LSHttpTool sendHttpData:str params:dic success:^(id responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];

        [self.LSPromptAlert dismissViewControllerAnimated:YES completion:nil];
        
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {

            if ([self.titleStr isEqualToString:@"项目"]) {
                
                NSMutableDictionary * dict = [NSMutableDictionary dictionary];
                dict[@"projectId"] = dic[@"resId"];
                dict[@"userId"] = [USER_DEFAULTS objectForKey:@"userid"];
                
                [LSHttpTool sendHttpData:@"projectDetail_app_project.im" params:dict success:^(id responseObject) {
                    if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {

                        SearchProjectInfoVC * SeaVC = [[SearchProjectInfoVC alloc]initWithNibName:@"SearchProjectInfoVC" bundle:nil];
                        SeaVC.dataDict = responseObject[@"data"];
                        SeaVC.projectData = [NSMutableArray arrayWithArray:responseObject[@"data"][@"commentsList"]];
                        SeaVC.tig = @"project";
                        
                        [self.navigationController pushViewController:SeaVC animated:YES];
                        
                        [self hideBubble];
                        
                    }else{

                        [self showSingleIconBubble:[responseObject objectForKey:@"msg"]];
                        
                    }
                    
                } failure:^(NSError *error) {

                    [self showSingleIconBubble:@"网络连接错误"];
                    
                }];
                
                
            }else if ([self.titleStr isEqualToString:@"资金"]){
                
                NSMutableDictionary *muDicParameter = [NSMutableDictionary dictionary];
                
                muDicParameter[@"fundsId"] = dic[@"resId"];
                
                if ([USER_DEFAULTS objectForKey:@"userid"] != nil) {
                    
                    muDicParameter[@"userId"] = [USER_DEFAULTS objectForKey:@"userid"];
                    
                }
                
                [LSHttpTool sendHttpData:@"fundsDetail_app_funds.im" params:muDicParameter success:^(id responseObject) {
                    if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {

                        SearchPriceDetail *Svc = [[SearchPriceDetail alloc] initWithNibName:@"SearchPriceDetail" bundle:nil];
                        
                        Svc.dicData = responseObject[@"data"];
                        Svc.commentsList = responseObject[@"data"][@"commentsList"];
                        Svc.tig = @"price";
                        [self.navigationController pushViewController:Svc animated:YES];

                        [self hideBubble];
                        
                    }else{

                        [self showSingleIconBubble:[responseObject objectForKey:@"msg"]];
                        
                    }
                    
                } failure:^(NSError *error) {

                    [self showSingleIconBubble:@"网络连接错误"];
                    
                }];
                
            }
            
        }else{

           [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
            
        }
        
    } failure:^(NSError *error) {
        
        // 跳转至支付成功页面
        LSPayResultVC * LSPayResult = [[LSPayResultVC alloc]init];
        [LSPayResult setCashTypeWithExchangeFailed];

        [self hideBubble];
    }];
    
}

#pragma mark - 余额支付
-(void)clickCashBtn{
    
    NSString * balanceStr = [self.LSPromptAlert.PromptAlertView.balanceLabel.text stringByReplacingOccurrencesOfString:@"￥"withString:@""];
    
    double balance = [balanceStr floatValue];
    
    if (balance < 1) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"支付失败"
                                                        message:@"余额不足！"
                                                       delegate:self
                                              cancelButtonTitle:@"取消"
                                              otherButtonTitles:@"立刻充值",nil];
        alert.tag = 20;
        [alert show];
        
    }else{
        
        if (isSetPayPass) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"支付失败"
                                                            message:@"未设置支付密码"
                                                           delegate:self
                                                  cancelButtonTitle:@"取消"
                                                  otherButtonTitles:@"立即设置",nil];
            alert.tag = 30;
            [alert show];
            
        }else{
            
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"余额支付" message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
            alert.alertViewStyle = UIAlertViewStylePlainTextInput;
            
            UITextField *title = [alert textFieldAtIndex:0];
            [title setSecureTextEntry:YES];
            title.borderStyle = UITextBorderStyleNone;
            title.textColor = [UIColor redColor];
            title.textAlignment = NSTextAlignmentCenter;
            title.font = [UIFont systemFontOfSize:16.0f];
            title.placeholder = @"请输入支付密码";
            
            
            [alert showAlertWithCompletionHandler:^(NSInteger buttonIndex) {
                if(buttonIndex == 1){
                    UITextField *tf=[alert textFieldAtIndex:0];
                    if (tf.text.length > 0) {
                        
                        [self showRoundProgressWithTitle:@"请稍后..."];
                        
                        NSMutableDictionary * dic = [NSMutableDictionary  dictionary];
                        dic[@"token"] = allConstMemberToken;
                        dic[@"payUserId"] = allConstMemberid;
                        dic[@"payWay"] = @"1";
                        dic[@"payMoney"] = @(price);
                        dic[@"resId"] = projectId;
                        dic[@"payPass"] = tf.text;
                        
                        NSString * str;
                        
                        if ([self.titleStr isEqualToString:@"项目"]) {
                            
                            str = @"buyProjectDetail_app_pay.im.lensum";
                            dic[@"resId"] = projectId;

                            
                        }else if ([self.titleStr isEqualToString:@"资金"]){
                            
                            str = @"buyFundsDetail_app_pay.im.lensum";
                            dic[@"resId"] = fundsId;
                            
                        }
                        
                        [LSHttpTool sendHttpData:str params:dic success:^(id responseObject) {
                            
                            [self.LSPromptAlert dismissViewControllerAnimated:YES completion:nil];

                            NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
                            
                            if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                                
                                if ([self.titleStr isEqualToString:@"项目"]) {
                                    
                                    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
                                    dict[@"projectId"] = dic[@"resId"];
                                    dict[@"userId"] = [USER_DEFAULTS objectForKey:@"userid"];
                                    
                                    [LSHttpTool sendHttpData:@"projectDetail_app_project.im" params:dict success:^(id responseObject) {
                                        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {

                                            SearchProjectInfoVC * SeaVC = [[SearchProjectInfoVC alloc]initWithNibName:@"SearchProjectInfoVC" bundle:nil];
                                            SeaVC.dataDict = responseObject[@"data"];
                                            SeaVC.projectData = [NSMutableArray arrayWithArray:responseObject[@"data"][@"commentsList"]];
                                            SeaVC.tig = @"project";
                                            
                                            [self.navigationController pushViewController:SeaVC animated:YES];

                                            [self hideBubble];
                                            
                                        }else{

                                            [self showSingleIconBubble:[responseObject objectForKey:@"msg"]];
                                            
                                        }
                                        
                                    } failure:^(NSError *error) {

                                        [self showSingleIconBubble:@"网络连接错误"];
                                        
                                    }];
                                    
                                    
                                }else if ([self.titleStr isEqualToString:@"资金"]){
                                    
                                    NSMutableDictionary *muDicParameter = [NSMutableDictionary dictionary];
                                    
                                    muDicParameter[@"fundsId"] = dic[@"resId"];
                                    
                                    if ([USER_DEFAULTS objectForKey:@"userid"] != nil) {
                                        
                                        muDicParameter[@"userId"] = [USER_DEFAULTS objectForKey:@"userid"];
                                        
                                    }
                                    
                                    [LSHttpTool sendHttpData:@"fundsDetail_app_funds.im" params:muDicParameter success:^(id responseObject) {
                                        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {

                                            SearchPriceDetail *Svc = [[SearchPriceDetail alloc] initWithNibName:@"SearchPriceDetail" bundle:nil];
                                            
                                            Svc.dicData = responseObject[@"data"];
                                            Svc.commentsList = responseObject[@"data"][@"commentsList"];
                                            Svc.tig = @"price";
                                            [self.navigationController pushViewController:Svc animated:YES];

                                            [self hideBubble];
                                            
                                        }else{

                                            [self showSingleIconBubble:[responseObject objectForKey:@"msg"]];
                                            
                                        }
                                        
                                    } failure:^(NSError *error) {

                                       [self showSingleIconBubble:@"网络连接错误"];
                                        
                                    }];
                                    
                                }
                                
                            }else{

                                [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                                
                            }
                            
                        } failure:^(NSError *error) {
                            
                            // 跳转至支付成功页面
                            LSPayResultVC * LSPayResult = [[LSPayResultVC alloc]init];
                            [LSPayResult setCashTypeWithCashFailed];

                            [self hideBubble];
                        }];
                        
                    }else{
                        
                        NSString *strMsg = @"密码不能为空";
                        
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:strMsg delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];
                        [alert show];
                        
                    }
                }
            }];
            
            
        }
        
    }
    
}

#pragma mark - alertview

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        [self.LSPromptAlert dismissViewControllerAnimated:YES completion:nil];
        
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        //充值
        LSRechargeVC * LSRecharge = [[LSRechargeVC alloc]init];
        
        switch (alertView.tag) {
            case 10:
                
                [self presentViewController:loginNAV animated:YES completion:nil];
                
                break;
                
            case 20:
                
                [self.navigationController pushViewController:LSRecharge animated:YES];
                
                break;
                
            case 30:
            {
                
                UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                ForgetPassWord *ForgetPassWord = [LoginAndRegister instantiateViewControllerWithIdentifier:@"forgetpassword"];
                ForgetPassWord.titleStr = @"修改支付密码";
                [self.navigationController pushViewController:ForgetPassWord animated:YES];
                
            }
                break;
                
            default:
                break;
        }
    }
    
    
}
#pragma mark - 网络请求
- (void)startSearch
{
    
    NSString * str;
    
    if ([self.titleStr isEqualToString:@"项目"]) {
        
        str = @"getMyoutProject_app_myHome.im";
        
    }else if ([self.titleStr isEqualToString:@"资金"]){
        
        str = @"getMyoutFunds_app_myHome.im";
    
    }else if ([self.titleStr isEqualToString:@"活动"]){
    
        str = @"getMyoutActivity_app_myHome.im";
        
    }else if ([self.titleStr isEqualToString:@"服务"]){
    
        str = @"getMyoutService_app_myHome.im";
    }
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,str];
    
    
//    NSLog(@"url:%@",strURl);
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//    NSLog(@"muDicParameters:%@",muDicParameters);
    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        //        NSLog(@"%@",dicInfo);
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            
            if (paggge == 1) {
                [self.tableView.mj_header endRefreshing];
                
                _aryInfo = [NSMutableArray arrayWithArray:[dicInfo objectForKey:@"data"][@"record"]];
                
                if (_aryInfo.count == 10) {
                    self.tableView.mj_footer.hidden = NO;
                }else {
                    self.tableView.mj_footer.hidden = YES;
                }
                
            }else {
                [self.tableView.mj_footer endRefreshing];
                NSArray *ary11 = [dicInfo objectForKey:@"data"][@"record"];
                for (int i = 0; i<ary11.count; i++) {
                    NSDictionary *dic1 = ary11[i];
                    [_aryInfo addObject:dic1];
                }
                if (ary11.count == 10) {
                    self.tableView.mj_footer.hidden = NO;
                }else {
                    self.tableView.mj_footer.hidden = YES;
                }
                
            }

            [self.tableView reloadData];
            [self hideBubble];
        }else {

            [self hideBubble];
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];

        [self showSingleIconBubble:error.localizedDescription];

    }];

}
@end
